<script setup>
import MovieLists from '@/components/MovieLists.vue'


import { findCategoryByIdAPI } from '@/apis/home.js'
import { useRoute } from 'vue-router'
import { findCategorySTAPI } from '@/apis/home.js'
import { findCategoryListAPI } from '@/apis/home.js'
import { ref } from 'vue'
const hotList = ref([])
const categoryInfo = ref([])
const route = useRoute()
const categoryList = ref([])
const id =route.params.id;




const getNewList = async () => {
    const res = await findCategoryListAPI(id)
    const resInfo = await findCategoryByIdAPI(id)
    hotList.value = res
    categoryInfo.value = resInfo
    console.log(res);
    console.log(resInfo);


    for (let i = 0; i < resInfo.children.length; i++) {

        const item = await findCategorySTAPI(resInfo.children[i].id)
        categoryList.value.push(item)

    }

    // console.log(categoryList);
}

getNewList()
</script>

<template>
    <div class="container">

        <div class="type_list_menu">

            <ul>
                <li><a href="/type/6.html"><i class=" rebboIcon iconfont icon-remen"></i>电影分类</a></li>
                <li><a href="/type/6.html">动作片</a></li>
                <li><a href="/type/6.html">爱情片</a></li>
                <li><a href="/type/6.html">恐怖片</a></li>
                <li><a href="/type/6.html">战争片</a></li>
            </ul>
        </div>


        <MovieLists :title="`热门` + categoryInfo.label">
            <ul class="movie_list">
                <li v-for="item in hotList" :key="item.id">
                    <RouterLink active-class="active" :to="`/detail/${item.id}`">
                        <div class="movie_head" :style="{ backgroundImage: 'url(' + item.pic + ')' }">
                            <span class="movie_test_left">{{ item.num == 0 ? "完结" : "更新至" + item.num + "集" }}</span><span
                                class="movie_test_right">{{ item.star }}</span>
                        </div>
                        <div class="movie_info">
                            <p>{{ item.title }}</p>
                            <span class="view-text">{{ item.des }}</span>
                        </div>
                    </RouterLink>
                </li>
            </ul>
        </MovieLists>


        <MovieLists v-for="outitem in categoryList" :key="outitem.id" :title="outitem.name">
            <ul class="movie_list">
                <li v-for="item in outitem.info" :key="item.id">
                    <RouterLink active-class="active" :to="`/detail/${item.id}`">
                        <div class="movie_head" :style="{ backgroundImage: 'url(' + item.pic + ')' }">
                            <span class="movie_test_left">{{ item.num == 0 ? "完结" : "更新至" + item.num + "集" }}</span><span
                                class="movie_test_right">{{ item.star }}</span>
                        </div>
                        <div class="movie_info">
                            <p>{{ item.title }}</p>
                            <span class="view-text">{{ item.des }}</span>
                        </div>
                    </RouterLink>
                </li>
            </ul>
        </MovieLists>







    </div>
</template>


<style scoped lang='scss'>
.container {
    .type_list_menu {
        height: 30px;
        margin-bottom: 10px;

        ul {
            list-style: none;
        }

        li {
            display: inline;

            a {
                font-size: 16px;
                line-height: 30px;
                text-decoration: none;
                padding: 10px 10px;

                &:hover {
                    color: $warnColor;
                }
            }
        }

    }


    .rebboIcon {
        font-size: 24px;
        color: #ff5f00;
    }

    .line {
        margin-left: 10px;
        margin-right: 10px;
    }


    // 设置文本超出使用省略号
    .view-text {
        display: inline-block;
        white-space: nowrap;
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }


    background: #fff;

    .pannel {
        display: flex;
        justify-content: space-between;

        .pannel_head {
            width: 400px;

            h2 {
                display: inline-block;

            }

            .more {
                padding-left: 15px;
            }



        }

        .right_menu {

            li {
                line-height: 70px;
                float: left;

                em {
                    color: #ff5f00;
                }
            }

        }

        a:hover {
            color: $xtxColor;
        }


    }

    .movie_list {
        display: flex;
        height: 850px;
        justify-content: space-between;
        flex-flow: row wrap;

        li {
            width: 19%;
            height: 50%;

            .movie_head {
                width: 100%;
                height: 70%;
                background-size: cover;
                background-position: center;

                position: relative;
                font-size: 15px;
                font-weight: bold;

                .movie_test_left {
                    color: #ff5f00;
                    position: absolute;
                    bottom: 8px;
                    padding-left: 5px
                }

                .movie_test_right {
                    color: #ff5f00;
                    position: absolute;
                    bottom: 8px;
                    right: 8px;
                }
            }

            .movie_info {
                margin-top: 5px;

                p {
                    font-size: 18px;
                    font-weight: bold;
                }

                span {
                    font-size: 14px;
                    color: #666;
                }

            }
        }
    }
}
</style>